package aiguigu1.one;

/**
 * ClassName: OneArrayTest
 * Package: aiguigu1.one
 * Description:
 *
 * @Author ZY
 * @Create 2024/9/9 20:29
 * @Version 1.0
 */
public class OneArrayTest {
    public static void main(String[] args) {
        //1.数组的声明与初始化
//        int num1 = 10;
//        int num2;//声明
//        num2 = 20;//初始化
        //1.1声明数组
//        double[] prices;
        //1.2数组的初始化
        //静态初始化：数值变量的赋值与数组元素的赋值操作分开进行
//        prices = new double[]{20.32,43.21,43.22};
//
//        String[] foods;
//        foods = new String[]{"冬瓜","西瓜"};

        //数组的声明和初始化
        //动态初始化：数值变量的赋值与数组元素的赋值操作同时进行
//        String[] foods = new String[4];

        //其他方式
//        int arr[]= new int[4];
//        int[] arr = {1,2,3,4};
//        System.out.println(prices[0]);
//        //数组的长度
//        System.out.println(prices.length);
//        //数组的遍历
//        for (int i = 0; i < foods.length; i++) {
//            System.out.println(foods[i]);
//        }
        //数组元素的默认初始化

        //整形数组元素的默认初始化
        int[] arr = new int[3];
        System.out.println(arr[0]);
        //浮点型数组元素的默认初始化
        double[] arr1 = new double[3];
        System.out.println(arr1[0]);
        //字符型数组元素的默认初始化
        char[] arr2 = new char[3];
//        System.out.println(arr2[0]);
        if (arr2[0] == 0){
            System.out.println("1111");
        }
        //boolean型数组元素的默认初始化
        boolean[] arr3 = new boolean[3];
        System.out.println(arr3[0]);
        //引用数据类型数组元素的默认初始化
        String[] arr4 = new String[3];
        if (arr4[0] == null){
            System.out.println("aaaa");
        }
//        int[] arr5 = new int[]{1,2,3};

        //数组的内存解析
        int[] arr6 = new int[]{1,2,3};
        int[] arr6_1 = arr6;
        arr6_1[1] = 10;
        for (int i=0;i< arr6.length;i++){
            System.out.println(arr6[i]);
        }
    }
}
